package org.example.exp2.exam6.deep;

import java.io.*;

public class Customer implements Serializable {
   private String name;
   private boolean sex;
   private int age;
   private Address customerAddress;

   public Customer(String name, boolean sex, int age, Address customerAddress) {
      this.name = name;
      this.sex = sex;
      this.age = age;
      this.customerAddress = customerAddress;
   }

   public Customer deepClone() throws IOException, ClassNotFoundException {
      //写入流中
      ByteArrayOutputStream bao = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(bao);
      oos.writeObject(this);

      //从流中读出
      ByteArrayInputStream bis = new ByteArrayInputStream(bao.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bis);
      return (Customer) ois.readObject();
   }

   public Address getCustomerAddress() {
      return customerAddress;
   }

   public String getName() {
      return name;
   }
}